import axios from 'axios';
import qs from 'querystring';

export const addUser = body => {
  return axios.post('/api/user/addUser', body);
};

export const updateUser = body => {
  return axios.post('/api/user/editUser', body);
};

export const getUsers = params => {
  if (params) {
    Object.keys(params).map(r => {
      if (!params[r] || params[r].length === 0) {
        delete params[r];
      }
    });
  }
  return axios.get(`/api/user/userList?${qs.stringify(params)}`);
};

export const getStaffList = params => {
  if (params && !params.search) {
    delete params.search;
  }
  return axios.get(`/api/user/staffList?${qs.stringify(params)}`);
};

export const unlockUser = uid => {
  return axios.post('/api/user/unlockUser', {
    // eslint-disable-next-line
    user_id: uid
  });
};

export const deleteUser = uid => {
  return axios.post('/api/user/deleteUser', {
    // eslint-disable-next-line
    user_id: uid
  });
};

export const resetPassword = body => {
  return axios.post('/api/user/resetPWD', body);
};

export const getAccounts = () => {
  return axios.get('/api/user/getAccountImformations');
};

export const setAccount = body => {
  return axios.post('/api/user/setAccount', body);
};

export const changePassword = body => {
  return axios.post('/api/user/changePassword', body);
};

export const getMessageSettings = () => {
  return axios.get('/api/user/getMessageSettings');
};

// 获取用户偏好的表头
export const getColumnsConfig = key => {
  return axios.get(`/api/user/columnsConfig?key=${key}`);
};

// 设置用户偏好的表头
export const setColumnsConfig = body => {
  return axios.post('/api/user/columnsConfig', body);
};
